/*********************************************************
          File Name:test.c
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Fri 07 Aug 2015 08:34:43 PM CST
**********************************************************/

#include <stdio.h>
#include <stdlib.h>
#include "hash.h"

int main(int argc, char *argv[])
{
        if(argc != 2)
        {
                fprintf(stderr, "%s path(configuration file path)\n", argv[0]);
                exit(1);
        }
        hash_table_t *ht = hash_table_new();
        if(ht == NULL)
                exit(1);
        size_t offset = 0; 
        if(file2hash(argv[1], ht, &offset) == -1)
        {
                hash_table_delete(ht);
                exit(1);
        }

        int size = 0, i;
        hash_node_t **node = NULL;

        hash_add(ht, "pisces", "89");
        printf("get %s by key \"f\"\n", hash_getval(ht, "f"));
        hash_remove(ht, "f");
        hash_add(ht, "pisces", "3890929");

        size = hash_getpairs(ht, &node);

        for(i = 0; i < size; i++)
                printf("%-32s\t-->\t%-32s\n", node[i]->key, node[i]->val);

        hash_table_delete(ht);
        free(node);

        return 0;
}
